
import requests
from PIL import Image
from io import BytesIO
from diffusers import LDMSuperResolutionPipeline
import torch

# device = "cuda" if torch.cuda.is_available() else "cpu"
model_id = "CompVis/ldm-super-resolution-4x-openimages"

# load model and scheduler
pipeline = LDMSuperResolutionPipeline.from_pretrained(model_id)
pipeline = pipeline.to("cuda")
pipeline.enable_xformers_memory_efficient_attention()
# pipeline.enable_sequential_cpu_offload()
pipeline.enable_attention_slicing(1)
# pipeline.vae.enable_tiling()
# let's download an  image
low_res_img = Image.open("../../data/original_2023_07_22_12_32_24.png").convert("RGB")
low_res_img = low_res_img.resize((512, 256))

# run pipeline in inference (sample random noise and denoise)
upscaled_image = pipeline(low_res_img, num_inference_steps=10, eta=1).images[0]
# save image
upscaled_image.save("../../data/ldm_generated_image.png")
